package com.csnf.dao;

import com.csnf.entity.User;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class UserDao {

    public List<User> getAll() throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:mysql:///tmalldemodb", "root", "root123");
        PreparedStatement ps = conn.prepareStatement("select * from user");
        ResultSet rs = ps.executeQuery();
        List<User> userList = new ArrayList<>();
        while(rs.next()){
            User user =new User() ;
            user.setUser_id(rs.getInt("user_id"));
            user.setUser_name(rs.getString("user_name"));
            user.setUser_nickname(rs.getString("user_nickname"));
            userList.add(user);
        }
        return userList;
    }

}
